import baseComponents from './baseComponents'

function checkCardMove(evt){
  // 获取拖动元素的索引和目标位置的索引
  const dragIndex = evt.draggedContext.index;
  const targetIndex = evt.relatedContext.index;
  // console.log(dragIndex, targetIndex);
  if (targetIndex === 0) {
      return 1;
  }
}

function checkItemMove(evt){
  // console.log('evt', evt)
  let that = this
  const targetIndex = evt.relatedContext.index;
  let card = that.findCard(evt.relatedContext.element)
  // console.log('card', card)
  if(card){
    let startDragIndex = card.__config__.startDragIndex
    // console.log('targetIndex',targetIndex, 'startDragIndex', startDragIndex)
    if(startDragIndex !== undefined && targetIndex < startDragIndex-1){
      return false
    }
    if (targetIndex === startDragIndex-1) {
      return 1
    }
  }
}

let leftComponents = [{
  groupName: 'card',
  checkMove: checkCardMove,
  list: baseComponents.filter(t => t.__config__.layout === 'tsCard')
},
{
  groupName: 'item',
  checkMove: checkItemMove,
  list: baseComponents.filter(t => t.__config__.layout !== 'tsCard')
}]

export default function getLeftComponents(){
  leftComponents.forEach(t=>{
    if(t.checkMove) t.checkMove = t.checkMove.bind(this)
  })
  return leftComponents
}
